package stu.day19_day24.day20;

public class LeetCode605 {
    public boolean canPlaceFlowers(int[] flowerbed, int n) {

        int len = flowerbed.length;
        int index = 0;
        int num = 0;
        while (index < len) {

            if (flowerbed[index] == 1) {

                index += 2;

            } else if (flowerbed[index] == 0) {

                if ((index + 1) >= len) {

                    num += 1;
                    index += 2;

                } else {
                    if (flowerbed[index + 1] == 0) {
                        num += 1;
                        index += 2;
                    } else {
                        index += 3;
                    }

                }
            }
        }

        return num>=n;

    }

    public static void main(String[] args) {
        LeetCode605 test = new LeetCode605();
        int[] x = new int[]{1,0,0,0,1};
        int y =2;
        System.out.println(test.canPlaceFlowers(x,y));

    }
}
